﻿
@{
    ViewBag.Title = "MonthReportDataConfirmPreview";
    Layout = "~/Views/Shared/_Form.cshtml";
}

<form id="form1">
    <div style="padding-top: 20px; margin-right: 55px;">
        <table class="form">
            <tr>
                <th class="formTitle">月份：</th>
                <td class="formValue">
                    <label id="lblYearMonth"></label>
                </td>
            </tr>
            <tr>
                <th class="formTitle">费用：</th>
                <td class="formValue">
                    <label id="lblCalcZje"></label>
                </td>
            </tr>
            <tr>
                <th class="formTitle">补差调整：</th>
                <td class="formValue">
                    <input id="balance" type="text" class="form-control" placeholder="调整金额" />
                </td>
            </tr>
            <tr>
                <th class="formTitle" valign="top" style="padding-top: 5px;">
                    调整原因：
                </th>
                <td class="formValue">
                    <textarea id="balanceReason" class="form-control" style="height: 60px;"></textarea>
                </td>
            </tr>
            <tr>
                <th class="formTitle">费用合计：</th>
                <td class="formValue">
                    <label id="lblResultZje"></label>
                </td>
            </tr>
        </table>
    </div>
</form>

<script type="text/javascript">
    var year = $.request("year");
    var month = $.request("month");
    var calcZje = $.request("calcZje");
    var isregenerate = $.request("isregenerate"); //重新生成 标志

    $('#lblYearMonth').html(year + '-' + $.zeroPrefixInteger(month, 2));
    $('#lblCalcZje').html(parseFloat(calcZje).toFixed(2));
    $('#lblResultZje').html(parseFloat(calcZje).toFixed(2));

    $('#balance').keyup(function () {
        //重新计算合计
        var tzje = $('#balance').val();
        if (tzje) {
            if (isNaN(parseFloat(tzje))) {
                $('#lblResultZje').html(parseFloat(calcZje).toFixed(2));
            }
            else {
                $('#lblResultZje').html((parseFloat(calcZje) + parseFloat(tzje)).toFixed(2));
            }
        }
        else {
            $('#lblResultZje').html(parseFloat(calcZje).toFixed(2));
        }
    });

    //
    function submitMonthReport() {
        var balance = $('#balance').val();
        var balanceReason = $('#balanceReason').val();
        var resultZje = $('#lblResultZje').html();
        var details = $.currentWindow().details;
        if (!year || !month) {
            $.modalAlert("日期错误，请重试", 'error');
            return;
        }
        if (!calcZje || !resultZje) {
            $.modalAlert("费用错误，请重试", 'error');
            return;
        }
        if (!isNaN(parseFloat(resultZje)) && parseFloat(resultZje) <= 0) {
            $.modalAlert("费用合计结果应为正数，请确认", 'error');
            return;
        }
        if (!balanceReason && balance) {
            $.modalAlert("补差，请填写原因", 'error');
            return;
        }
        if (!details || !details.length || details.length == 0) {
            $.modalAlert("未获取到费用", 'error');
            return;
        }
        $.submitForm({
            url: '/ReportManage/Report/SubmitMonthReportData',
            param: {
                year: year, month: month, calcZje: calcZje, balance: balance, balanceReason: balanceReason
                , resultZje: resultZje, details: details, isregenerate: isregenerate
            },
            success: function (ajaxresp) {
                $.currentWindow().$('#btn_search').trigger('click');
            }
        });
    }

</script>